package extend.db.shard.rule;

import extend.db.base.Query;
import extend.db.shard.ShardRule;
import java.util.Map;

/**
 * 取摸分片规则
 * <B>说明：</B>
 * <pre>
 *  略
 * </pre>
 * <B>示例：</B>
 * <pre>
 *  略
 * </pre>
 * <B>日志：</B>
 * <pre>
 *  略
 * </pre>
 * <B>注意事项：</B>
 * <pre>
 *  略
 * </pre>
 */
public class Mod implements ShardRule
{
    /**
     * 去摸值
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    private int mod = 2;

    protected String[] fields;

    public Mod()
    {

    }

    public Mod(String... fields)
    {
        this.fields = fields;
    }

    public void setMod(int mod)
    {
        this.mod = mod;
    }

    @Override
    public String[] getFields()
    {
        return  this.fields;
    }

    @Override
    public String getSequence(Query query,Map<String, Object> values)
    {

        int roleId = (int)values.get("RoleId");
        int mod = roleId % this.mod;
        return String.valueOf(mod);
    }
}
